const utils = require('../libs/utils.js');
const BaseService = require('../libs/baseService.js');
const MsgTemplate = require('../models/msg_template.js');

let service = new BaseService();

service.add = async (ctx, next) => {
    try {
        let data = JSON.parse(ctx.request.body);
        let record = await MsgTemplate.schema.find({app_id: data.app_id}).exec();
        if (!record) {
            await MsgTemplate.schema(data).save();
            service.backSuccess(ctx, "新增消息推送配置模板成功。");
        } else {
            throw new Error("已有该应用推送模板配置了！");
        }
    } catch(e) {
        //
        service.backError(ctx, 500 , e.message);
    }

}

service.edit = async (ctx, next) => {

}

service.getList = async (ctx, next) => {
    service.backSuccess(ctx, {});
}

service.delete  = async (ctx, next) => {

}


module.exports = service;